package com.itany.corejava.code06_面向对象.继承;

/**
 * @author 石小俊
 * @date 2024年01月16日 15:24
 */
public class MotorVehicle {

    private String no;  // 车牌号
    private String brand;   // 汽车品牌

    public MotorVehicle() {
    }

    public MotorVehicle(String no, String brand) {
        this.no = no;
        this.brand = brand;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    void show() {
        System.out.println("这是一辆" + brand + "机动车,车牌号为:" + no);
    }
}

class Car extends MotorVehicle {
    private String type;    // 型号

    public Car(String no, String brand, String type) {
        super(no, brand);
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    /**
     * 方法重写,子类与父类方法的方法名、参数列表、返回值类型必须一致
     * 在方法名相同的前提下
     * 如果参数不同,调用方法时根据传递的不同参数调用不同方法,相当于方法重载
     * 如果方法返回值不同,是直接报错
     * 关于修饰符:子类方法的修饰符范围不能小于父类的
     * 子类不能抛出比父类更大的异常
     */
    public void show() {
        System.out.println("这是一辆" + getBrand() + "牌" + type + "小轿车,车牌号为:" + getNo());
    }

}

class Bus extends MotorVehicle {
    private int seatCount;  // 座位数

    public Bus(String no, String brand, int seatCount) {
        super(no, brand);
        this.seatCount = seatCount;
    }

    public int getSeatCount() {
        return seatCount;
    }

    public void setSeatCount(int seatCount) {
        this.seatCount = seatCount;
    }

    public void show() {
        System.out.println("这是一辆" + getBrand() + "牌" + seatCount + "座的公共汽车,车牌号为:" + getNo());
    }
}

class TestMotorVehicle {
    public static void main(String[] args) {
        Car car = new Car("苏A00001", "BMW", "X6");
        car.show();
        Bus bus = new Bus("苏A00002", "金龙", 35);
        bus.show();

    }
}
